#! /usr/bin/env python
# -*- coding: utf-8 -*-

# *************************************************************
#     Filename @  flock_lock.py
#       Author @  Huoty
#  Create date @  2016-06-01 13:13:22
# *************************************************************

import fcntl
import time

fobj = open("test.txt", "r")
fcntl.flock(fobj, fcntl.LOCK_UN)
print("------------ unlock")
fcntl.flock(fobj, fcntl.LOCK_EX)
print("------------ locked")
# 文件 close 之后，文件锁也会失效
#fobj.close()
time.sleep(20)
fcntl.flock(fobj, fcntl.LOCK_UN)
fobj.close()

# 进程结束后，文件锁也会失效
